package org.lanqiao.api.admin;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.pojo.PageModel;
import org.lanqiao.pojo.UserPOJO;
import org.lanqiao.service.AdminServiceImpl;

/**
 * 添加用户
 * Servlet implementation class AddUserServlet
 */
@WebServlet("/api/admin/AddUserServlet")
public class AddUserServlet extends HttpServlet {
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		String uaername=request.getParameter("Name");
		String password=request.getParameter("Password");
		String sex=request.getParameter("Sex");		
		String age=request.getParameter("Age");
		String address=request.getParameter("Address");
		String birthday=request.getParameter("Birthday");
		String photo=request.getParameter("Photo");
		String telphone=request.getParameter("Tel");
		String commit=request.getParameter("Commit");
		
		UserPOJO user=new UserPOJO();
		user.setUserName(uaername);
		user.setPassword(password);
		user.setSex(sex);
		user.setAge(age);
		user.setAddres(address);
		user.setBirthday(birthday);
		user.setPhoto(photo);
		user.setTelphone(telphone);
		user.setComment(commit);
		/**
		 * 调用查询用户
		 */
		AdminServiceImpl abc=new AdminServiceImpl();
		JsonResult result=null;
		try {
			int model=abc.adduser(user);
			if(model>0){
				result=new JsonResult("添加成功",Constants.STATUS_SUCCESS);
			}else {
				result=new JsonResult("添加错误",Constants.STATUS_UNFOUND);
			}
		} catch (Exception e) {
			result=new JsonResult("添加异常",Constants.STATUS_FAILURE);
		}
		JsonResultWriter.writer(response, result);
	}
}
